/*****************************************************************************
 *   Copyright (C) 2008 John Schember <john@nachtimwald.com>                 *
 *                                                                           *
 *   This file is part of niwbillmanager.                                    *
 *                                                                           *
 *   niwbillmanager is free software: you can redistribute it and/or         *
 *   modify it under the terms of the GNU General Public License as          *
 *   published by the Free Software Foundation, either version 3 of the      *
 *   License, or (at your option) any later version.                         *
 *                                                                           *
 *   niwbillmanager is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with niwbillmanager. If not, see                                  *
 *   <http://www.gnu.org/licenses/>.                                         *
 *****************************************************************************/

#include <QPluginLoader>

#include "plugin.h"

Plugin::Plugin()
{
    m_name = "";
    m_credits = "";
    m_description = "";
    m_version = "";
    m_license = "";
    m_enabled = false;
    m_location = "";
    m_pluginInterface = 0;
}

Plugin::~Plugin()
{
    unloadPlugin();
}

void Plugin::loadPlugin(NiwBillManager *lib)
{
    QPluginLoader pluginLoader;

    pluginLoader.setFileName(m_location);
    if (pluginLoader.load()) {
        m_pluginInterface = qobject_cast<Qt4UiPluginInterface *>
            (pluginLoader.instance());
        m_pluginInterface->setLib(lib);
    }
}

void Plugin::unloadPlugin()
{
    if (m_pluginInterface) {
        delete m_pluginInterface;
    }
    m_pluginInterface = 0;
}

QString Plugin::getName()
{
    return m_name;
}

QString Plugin::getCredits()
{
    return m_credits;
}

QString Plugin::getDescription()
{
    return m_description;
}

QString Plugin::getVersion()
{
    return m_version;
}

QString Plugin::getLicense()
{
    return m_license;
}

bool Plugin::isEnabled()
{
    return m_enabled;
}

QString Plugin::getLocation()
{
    return m_location;
}

Qt4UiPluginInterface *Plugin::getPluginInterface()
{
    return m_pluginInterface;
}

void Plugin::setName(QString name)
{
    m_name = name;
}

void Plugin::setCredits(QString credits)
{
    m_credits = credits;
}

void Plugin::setDescription(QString description)
{
    m_description = description;
}

void Plugin::setVersion(QString version)
{
    m_version = version;
}

void Plugin::setLicense(QString license)
{
    m_license = license;
}

void Plugin::setEnabled(bool enabled)
{
    m_enabled = enabled;
}

void Plugin::setLocation(QString location)
{
    m_location = location;
}
